<!--
 * @Author: your name
 * @Date: 2020-02-25 13:32:39
 * @LastEditTime: 2020-03-19 13:47:30
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \福路德扫码系统\html\cksm.html
 -->
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0,viewport-fit=cover" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Hello APP</title>
    <link rel="stylesheet" type="text/css" href="../css/vant.css">
    <link rel="stylesheet" type="text/css" href="../css/base.css" />
    <link rel="stylesheet" type="text/css" href="../css/local.css" />
    <script type="text/javascript" src="../script/jquery.js"></script>
    <script type="text/javascript" src="../script/layer/mobile/layer.js"></script>
    <script type="text/javascript" src="../script/vue.min.js"></script>
    <script type="text/javascript" src="../script/vant.min.js"></script>
    <script type="text/javascript" src="../script/fastclick.js"></script>
    <script type="text/javascript" src="../script/base.js"></script>
    <script type="text/javascript" src="../script/app-tree.js"></script>
    <style type="text/css">
        .part {
            padding: 15px 15px 0 15px;
        }

        .part .pf {
            border-radius: 6px;
            box-shadow: 0px 1px 5px rgb(200, 198, 198);
            background-color: #fff;
            overflow: hidden;
        }

        .textarea {
            display: block;
        }

        .label {
            padding: 10px 16px;
        }

        .ap-f {
            border-bottom: 1px solid #f7f7f7;
        }

        .mark {
            padding: 17px 15px;
        }

        .mark1 {
            padding: 17px 5px 17px 15px;
            position: relative;
        }

        .f-sub {
            color: #969799;
            font-size: 13px;
            margin-top: 4px;
        }

        .line {
            position: relative;
            width: 30px;
        }

        .line1 {
            width: 60px;
        }

        .line-sq {
            display: inline-block;
            width: 11px;
            height: 11px;
            border-radius: 6px;
            background: #d6d6d6;
            position: absolute;
            left: 0;
            top: 12px;
        }

        .line-li {
            display: inline-block;
            width: 1px;
            background: #d6d6d6;
            position: absolute;
            left: 5px;
            top: -17px;
            bottom: -17px;
        }

        .line-li1 {
            display: inline-block;
            background: #d6d6d6;
            position: absolute;
            top: 52px;
            left: 35px;
            width: 3px;
            bottom: 10px;
        }

        .pd {
            padding: 16px 0;
        }

        .ap-r {
            text-align: right;
            padding-right: 10px;
            /* margin: -8px 0; */
            padding-top: 10px;
        }

        .ap-d {
            text-align: right;
            padding-right: 10px;
            color: #ccccce;
            font-size: 13px;
            float: right;
            padding-top: 3px;
        }

        .img {
            width: 34px;
            height: 34px;
            line-height: 34px;
            text-align: center;
            font-size: 12px;
            color: #fff;
            background-color: #3396fb;
            border-radius: 6px;
            margin: 0 auto;
            position: relative;
            user-select: none;
        }

        .img1 {
            width: 44px;
            height: 44px;
            line-height: 44px;
            text-align: center;
            font-size: 13px;
            color: #fff;
            background-color: #3396fb;
            border-radius: 6px;
            position: relative;
            user-select: none;
        }

        .dis-ib {
            display: inline-block;
            vertical-align: middle;
            text-align: center;
            min-width: 40px;
        }

        .dis2-ib {
            display: inline-block;
            vertical-align: middle;
            padding-bottom: 3px;
            text-align: center;
        }

        .dis3-ib {
            display: inline-block;
            margin: 0 6px;
            color: #969799;
            vertical-align: top;
            padding-top: 7px;
            text-align: center;
        }

        .ap-n {
            padding-top: 2px;
            font-size: 13px;
            color: #969799;
            text-align: center;
        }

        .bottom {
            width: 100%;
            padding: 8px 15px;
            /* position: absolute; */
            /* bottom: 0; */
        }

        .part-white {
            padding: 15px;
            background-color: #fff;
            position: relative;
        }

        .title {
            line-height: 40px;
            font-size: 18px;
        }

        .title-sub {
            color: #aaacac;
            font-size: 13px;
        }

        .title-read {
            color: #3396fb;
            font-size: 13px;

        }

        .title-unread {
            color: #788a8a;
            font-size: 13px;
        }

        .ap-res {
            color: #a3a3a3;
            font-size: 15px;
            padding-top: 6px;
        }

        .ap-res1 {
            color: #c31616;
            font-size: 15px;
            padding-top: 6px;
        }

        .ap-img {
            position: absolute;
            right: 20px;
            bottom: -38px;
            width: 88px;
            opacity: 0.4;
        }

        .form-row {
            padding: 4px 16px;
        }

        .form-label {
            color: #808991;
            font-size: 13px;
            user-select: none;
        }

        .form-content {
            padding-top: 5px;
        }

        .npd {
            padding-top: 0;
            overflow-x: auto;
        }

        .pl {
            color: #969799;
            font-size: 16px;
            margin: 6px 2px 18px 0;
            min-height: 25px;
            border-bottom: 1px solid #ebedf0;
        }

        .sf {
            width: 16px;
            background: #fff;
            padding: 2px;
            border-radius: 8px;
            position: absolute;
            right: -5px;
            bottom: -2px;
        }

        .select {
            color: #3396fb;
            float: right;
            font-size: 13px;
            padding-top: 3px;
            vertical-align: middle;
        }

        .select a {
            vertical-align: middle;
        }

        .select img {
            width: 16px;
            vertical-align: middle;
        }

        .hq {
            padding: 10px 10px 0 0;
        }

        .wh {

            white-space: nowrap;
            overflow-x: auto;
            padding-right: 10px;
        }

        .plpd {
            padding-bottom: 5px;
        }

        .pictitle {
            line-height: 24px;
            color: #646566;
            user-select: none;
        }

        .piccontent {
            padding-top: 10px;
            overflow: hidden;
        }

        .van-uploader__preview {
            margin-right: 15px;
        }

        .no {
            text-align: center;
            color: #808991;
            font-size: 14px;
        }

        .li1 {
            top: 15px;
        }

        .li2 {
            bottom: 24px;
        }

        .da-c {
            color: #c31616;
        }

        .danger .van-field__control {
            color: #c31616;
        }

        .danger .van-field__label {
            color: #808991;
        }

        .ac-1 {
            color: #03b553;
        }

        .ac-2 {
            color: #c31616;
        }

        .checkbox {
            padding: 25px 5px 10px 10px;
        }

        .jl-remark {
            padding: 5px 0;
            color: #3396fb;
        }

        .memo-l {
            border-bottom: 1px solid rgb(235, 237, 240);
            padding: 4px 0;
        }

        .memo-l:last-child {
            border-bottom: 0;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak>
        <div class="box">
            <van-nav-bar-main title="额外取样" left-arrow @click-left="onClickLeft"></van-nav-bar-main>
            <div class="content" style="padding-bottom: 20px;">
                <div>
                    <div class="part-white">
                        <div class="title">{{creater}}提交的额外取样</div>
                        <div class="ap-res">{{form.isFinish==0?'正在审批中':(form.isFinish==1?'审批已通过':'审批已拒绝')}}</div>
                        <!-- <div style="padding-bottom: 10px;"></div> -->
                        <!-- <div class="title-read" v-if="readArray.length">
                            <span v-for="(row,index) in readArray">{{row.LogCount}}<span
                                    v-if="index != readArray.length - 1">,</span></span>已读
                        </div>
                        <div class="title-unread" v-if="unReadArray.length">
                            <span v-for="(row,index) in unReadArray">{{row.Approver}}<span
                                    v-if="index != unReadArray.length - 1">,</span></span>未读
                        </div> -->
                        <img class="ap-img" v-if="form.isFinish" src="../image/ap-1.png" />
                    </div>
                    <div class="part">
                        <div class="pf">
                            <div class="form-row">
                                <div class="form-label">批次号</div>
                                <div class="form-content">{{form.Batch}}</div>
                            </div>
                            <div class="form-row">
                                <div class="form-label">取样数量</div>
                                <div class="form-content">{{form.Qty}}</div>
                            </div>
                            <div class="form-row">
                                <div class="form-label">产品名称</div>
                                <div class="form-content">{{form.ProductName1}}</div>
                            </div>
                            <div class="form-row">
                                <div class="form-label">操作日期</div>
                                <div class="form-content">{{form.OperateDate}}</div>
                            </div>
                            <div class="form-row">
                                <div class="form-label">异常原因</div>
                                <div class="form-content">{{form.YCReason}}</div>
                            </div>
                            <div class="form-row">
                                <div class="form-label">类型</div>
                                <div class="form-content">{{form.Type}}</div>
                            </div>
                            <div class="form-row">
                                <div class="form-label">实验项目</div>
                                <div class="form-content">{{form.Items}}</div>
                            </div>
                            <div class="form-row" v-if="form.Items1">
                                <div class="form-label">具体实验项目</div>
                                <div class="form-content">{{form.Items1}}</div>
                            </div>
                        </div>
                    </div>
                    <div>
                        <div class="part" v-for="approvalRow in approvalList">
                            <div class="pf">
                                <div class="label">流程</div>
                                <div class="pd">
                                    <div>
                                        <div class="flex-box f-r">
                                            <div class="mark1 npd">
                                                <div class="line1">
                                                    <div>
                                                        <div class="dis-ib">
                                                            <div class="img1"><span>{{creater}}</span><img class="sf"
                                                                    src="../image/success.png" />
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="line-li1"></div>
                                                </div>

                                            </div>
                                            <div class="flex-main npd">
                                                <div>
                                                    <div>
                                                        <span>发起审批</span>
                                                        <span
                                                            class="ap-d">{{createTime.split('.')[0].replace(/T/g,'')}}</span>
                                                    </div>
                                                    <div class="f-sub">{{creater}}</div>
                                                </div>
                                                <div class="pl"></div>
                                            </div>
                                        </div>
                                    </div>
                                    <div v-for="(row,index) in approvalRow.approvalNodeList">
                                        <div class="flex-box f-r">
                                            <div class="mark1 npd">
                                                <div class="line1">
                                                    <div>
                                                        <div class="dis-ib">
                                                            <div class="img1">
                                                                <span
                                                                    v-if="row.node.length == 1 && row.node[0].CurrentApprovalIDs.length == 1 && row.type == 0">{{row.node[0].CurrentApprovalIDs[0]}}</span>
                                                                <van-icon v-else-if="row.type == 1" name="volume-o"
                                                                    size="28px" style="padding-top: 7px;">
                                                                </van-icon>
                                                                <van-icon v-else name="friends-o" size="28px"
                                                                    style="padding-top: 7px;">
                                                                </van-icon>
                                                                <img class="sf"
                                                                    v-if="approvalRow.level == row.index - 2 && row.type == 1 && row.node[0].Approve != 0"
                                                                    src="../image/success.png" />
                                                                <img class="sf"
                                                                    v-if="approvalRow.level >= row.index - 1"
                                                                    :src="getApprovalTagImg(row)" />
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="line-li1"
                                                        v-if="index != approvalRow.approvalNodeList.length - 1">
                                                    </div>
                                                </div>

                                            </div>
                                            <div class="flex-main npd">
                                                <div>
                                                    <div class="hq" v-if="row.showMore">
                                                        <!-- 会签 -->
                                                        <div class="wh"
                                                            v-if="row.node.length > 1 && checkIsSingle(row)">
                                                            <div class="dis2-ib" v-for="(item,itemIndex) in row.node">
                                                                <div class="dis-ib">
                                                                    <div class="img">
                                                                        <span>{{cutStr(item.CurrentApprovalIDs[0])}}</span>
                                                                        <img class="sf"
                                                                            v-if="item.Approver && item.Approver == item.CurrentApprovalIDs[0] && approvalRow.level >= row.index - 1 && item.Approve != 0"
                                                                            :src="item.Approve == 1?'../image/success.png':'../image/fail.png'" />
                                                                    </div>
                                                                    <div class="ap-n">
                                                                        {{item.CurrentApprovalIDs[0]}}</div>
                                                                </div>
                                                                <div class="dis3-ib"
                                                                    v-if="itemIndex != row.node.length - 1 && row.type == 0">
                                                                    +</div>
                                                                <div class="dis3-ib" v-if="row.type == 1">
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="pl">
                                                        <div class="plpd" v-for="item in row.node">
                                                            <div>
                                                                <span v-if="item.ApprovalContent"
                                                                    :class="'ac-' + item.Approve">{{item.Approver}}:</span>
                                                                <span v-if="item.ApprovalContent"
                                                                    :class="'ac-' + item.Approve">"{{item.ApprovalContent}}"</span>
                                                            </div>

                                                            <div class="piccontent" v-if="item.Imgs">
                                                                <div class="van-uploader">
                                                                    <div class="van-uploader__wrapper">
                                                                        <div class="van-uploader__preview"
                                                                            v-for="(imgItem,imgItemIndex) in (item.Imgs?item.Imgs.split(','):[])">
                                                                            <div class="van-image van-uploader__preview-image"
                                                                                style="overflow: hidden; border-radius: 4px;width:60px;height:60px;"
                                                                                @click="previewItemImage(item.Imgs,imgItemIndex,3)">

                                                                                <img :src="serverIP + imgItem"
                                                                                    class="van-image__img"
                                                                                    style="object-fit: cover;" />
                                                                            </div>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            </div>

                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>

                                        <div class="flex-box f-r"
                                            v-if="index == approvalRow.approvalNodeList.length - 1">
                                            <div class="mark1 npd">
                                                <div class="line1">
                                                    <div>
                                                        <div class="dis-ib">
                                                            <div class="img1">
                                                                <span>备注</span>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="line-li1"
                                                        v-if="index != approvalRow.approvalNodeList.length - 1">
                                                    </div>
                                                </div>
                                            </div>

                                            <div class="flex-main npd">
                                                <div>
                                                    <div>
                                                        <div>
                                                            <span style="vertical-align: middle;">备注</span>
                                                        </div>
                                                    </div>
                                                    <div class="pl">
                                                        <div class="jl-remark" v-if="editRemark && !form.memo"
                                                            @click="addRemark">添加备注</div>
                                                        <div class="jl-remark" v-if="form.memo">
                                                            <div class="piccontent">
                                                                <div class="van-uploader">
                                                                    <div class="van-uploader__wrapper">
                                                                        <div class="van-uploader__preview"
                                                                            v-for="(imgItem,imgItemIndex) in form.memoImg">
                                                                            <div class="van-image van-uploader__preview-image"
                                                                                style="overflow: hidden; border-radius: 4px;width:60px;height:60px;"
                                                                                @click="previewImage(imgItemIndex,2)">

                                                                                <img :src="serverIP + imgItem"
                                                                                    class="van-image__img"
                                                                                    style="object-fit: cover;" />
                                                                            </div>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                            <div class="memo-l" v-for="item in splitMemo()" v-if="item"
                                                                @click="addRemark">
                                                                <div><span>{{item.split('#')[0]}}</span></div>

                                                                <div style="color: #ccccce;font-size: 13px;">
                                                                    <span>{{item.split('#')[1]}}</span>
                                                                </div>

                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>


                <div class="bottom" v-if="!form.isFinish">
                    <div class="flex-main">
                        <van-row gutter="30">
                            <van-col :span="12">
                                <van-button block :square="false" :disabled="ifConfirm" :loading="ifConfirm"
                                    @click="dealApproval(1)">输入审核意见或确认同意</van-button>
                            </van-col>
                            <van-col :span="12">
                                <van-button block :square="false" :disabled="ifConfirm" :loading="ifConfirm"
                                    @click="dealApproval(2)">拒绝</van-button>
                            </van-col>
                        </van-row>
                    </div>
                </div>
            </div>
        </div>
</body>
<script type="text/javascript">
    var vm;
    apiready = function () {

        var UIAlbumBrowser = api.require('UIAlbumBrowser');
        var photoBrowser = api.require('photoBrowser');
        var isOpenImg = false;
        var approvalConfigdata = '';
        var allCurrentApprovalIDs = [];

        api.addEventListener({
            name: 'keyback'
        }, function (ret, err) {
            if (!isOpenImg) {
                vm.onClickLeft();
            } else {
                photoBrowser.close();
            }

        });

        api.addEventListener({
            name: 'submitApproval'
        }, function (ret, err) {
            var index = ret.value.index;
            var content = ret.value.content; //审批意见
            var imgArray = ret.value.imgArray;

            vm.submitApproval(index, content);
        });

        api.addEventListener({
            name: 'submitRemark'
        }, function (ret, err) {
            var content = ret.value.content;
            var imgArray = ret.value.imgArray;
            var userids = [];
            for (var i in allCurrentApprovalIDs) {
                if (userids.indexOf(allCurrentApprovalIDs[i]) == -1) {
                    userids.push(allCurrentApprovalIDs[i])
                }
            }
            var obj = {
                Ck_ReviewID: vm.form.id,
                FRemarks: content,
                MemoImg: imgArray.join(),
                MsgUserIDs: userids.join()
            }
            APP.ajax('updateCkReviewRemarks', obj, function (res) {
                layer.open({
                    content: '备注添加成功',
                    skin: 'msg',
                    time: 2
                });
                APP.ajax('getCkReviewByID', { Ck_ReviewID: vm.form.id }, function (res) {
                    if (res.ds.length) {
                        vm.form.memo = res.ds[0].Memo;
                        vm.form.memoImg = res.ds[0].MemoImg ? res.ds[0].MemoImg.split(',') : [];
                    }
                })
            })
        });

        vm = new Vue({
            el: '#app',
            data: {
                ifConfirm: false,
                serverIP: 'http://' + APP.serverIP(),
                userData: APP.getUserInfo(),
                creater: '',
                finalResult: 0,
                readArray: [],
                unReadArray: [],
                form: {
                    id: api.pageParam.id || 0,
                    isFinish: '',
                    Batch: '',
                    Qty: '',
                    ProductName1: '',
                    ProductID: '',
                    userName: '',
                    userID: '',
                    OperateDate: '',
                    YCReason: '',
                    Type: '',
                    Items: '',
                    Items1: '',
                    Approve: '',
                    Approver: '',
                    ApproveTime: ''
                },
                timeout: 15,
                approvalList: [],
                createTime: '',
                approvalActions: [],
                personList: [],
                approvalID: 0,
                editRemark: true
            },
            created: function () {
                var that = this;
                //审核模板
                APP.ajax('getApproveModel', {}, function (res) {
                    console.log('getApproveModel', JSON.stringify(res))
                    var approvalActions = [];
                    for (var i in res.ds) {
                        if (res.ds[i].AppFormName == 'ApprovePage1') {
                            res.ds[i].name = res.ds[i].BillName;
                            approvalActions.push(res.ds[i])
                        }

                    }
                    that.approvalActions = approvalActions;

                    //人员列表
                    APP.ajax('getCkUserList', {}, function (res) {
                        // console.log('getCkUserList', JSON.stringify(res))

                        that.personList = res.ds;

                        if (that.form.id) {
                            that.initPageData();
                        }
                    })
                })

            },
            methods: {
                addRemark: function () {
                    var that = this;
                    if (that.editRemark) {
                        api.openWin({
                            name: 'editRemark',
                            url: 'editRemark.html',
                            reload: true,
                            slidBackEnabled: false,
                            allowEdit: true,
                            pageParam: {
                                img: that.form.memoImg
                            }
                        })
                    }

                },
                checkIsSingle: function (row) {
                    var that = this;
                    var x = true;
                    for (var i in row.node) {
                        if (row.node[i].CurrentApprovalIDs.length > 1) {
                            x = false;
                        }
                    }
                    return x;
                },
                getApprovalTagImg: function (row) {
                    var that = this;
                    if (row.node.length == 1) {
                        if (row.node[0].Approve == 0) {
                            return '../image/doing.png';
                        } else if (row.node[0].Approve == 1) {
                            return '../image/success.png';
                        } else if (row.node[0].Approve == 2) {
                            return '../image/fail.png';
                        }
                    } else {

                        var imgstr = '';
                        var z = 0;
                        for (var i in row.node) {
                            if (row.node[i].Approve == 1) {
                                z++;
                            }
                            if (row.node[i].Approve == 2) {
                                imgstr = '../image/fail.png';
                                break;
                            }
                        }
                        if (imgstr) {
                            return imgstr;
                        } else {
                            if (z == 0) {
                                imgstr = '../image/doing.png'
                            } else {
                                if (row.node.length == z) {
                                    imgstr = '../image/success.png'
                                } else {
                                    imgstr = '../image/doing.png';
                                }
                            }

                        }
                        return imgstr;
                    }
                },
                initPageData: function (apstatus) {
                    var that = this;
                    var obj1 = {
                        PlanID: that.form.id
                    }
                    // console.log('obj', JSON.stringify(obj1))
                    APP.ajax('getExtraQY', obj1, function (res) {
                        // console.log('getExtraQY', JSON.stringify(res))
                        if (res.ds.length) {
                            that.form.isFinish = res.ds[0].Approve == null ? 0 : 1
                            that.form.Batch = res.ds[0].Batch;
                            that.form.Qty = res.ds[0].Qty;
                            that.form.ProductName1 = res.ds[0].ProductName1;
                            that.form.ProductID = res.ds[0].ProductID;
                            that.form.userName = res.ds[0].userName;
                            that.form.userID = res.ds[0].userID;
                            that.form.OperateDate = res.ds[0].OperateDate.split('T')[0];
                            that.form.YCReason = res.ds[0].YCReason;
                            that.form.Type = res.ds[0].Type;
                            that.form.Items = res.ds[0].Items;
                            that.form.Items1 = res.ds[0].Items1;
                            that.finalResult = 0
                            that.approvalID = res.ds[0].APFlowID
                        } else {
                            layer.open({
                                content: '记录已删除',
                                skin: 'msg',
                                time: 2,
                                end: function () {
                                    api.closeWin()
                                }
                            });
                        }
                    })

                    var obj2 = {
                        P_PKValue: that.form.id,
                        P_TableName: 'CK_ExperimentPlan',
                    }
                    // console.log('obj2', JSON.stringify('obj2'))
                    APP.ajax('Select_FlowLog1', obj2, function (res) {
                        that.creater = res.ds[0].Creater
                        // console.log('Select_FlowLog1', JSON.stringify(res))
                        if (res.ds[res.ds.length - 1].Approve == 1) {
                            that.finalResult = 1;
                        }

                        var data = [];
                        allCurrentApprovalIDs = [];
                        var allCurrentApprovalIDs2 = [];
                        for (var i in res.ds) {

                            res.ds[i].CurrentApprovalIDs = res.ds[i].CurrentApprovalIDs.replace(/^,+/, "").replace(/,+$/, "").split(',');

                            allCurrentApprovalIDs = allCurrentApprovalIDs.concat(res.ds[i].CurrentApprovalIDs);
                            if (res.ds[i].FlowType != 1) {
                                allCurrentApprovalIDs2 = allCurrentApprovalIDs2.concat(res.ds[i].CurrentApprovalIDs);
                            }
                            for (var c in res.ds[i].CurrentApprovalIDs) {
                                var row = that.filterPersonList('UserID', res.ds[i].CurrentApprovalIDs[c])
                                if (row) {
                                    res.ds[i].CurrentApprovalIDs[c] = row.UserName;
                                }

                            }

                            if (data.indexOf(res.ds[i].AuditID) == -1) {
                                data.push(res.ds[i].AuditID);
                            }
                        }

                        var approvalList = [];
                        for (var n in data) {
                            var approvalNodeList = [];
                            var level = 0;
                            var finLevel = 0;
                            for (var i in res.ds) {
                                if (data[n] == res.ds[i].AuditID) {

                                    if (res.ds[i].Approve == 0 && !level) {
                                        level = res.ds[i].ApprovalSort;
                                    }

                                    if (res.ds[i].Approve == 1 && i == res.ds.length - 1) {
                                        level = res.ds[i].ApprovalSort;
                                    }

                                    if (res.ds[i].Approve == 2 && !finLevel) {
                                        finLevel = res.ds[i].ApprovalSort;
                                    }

                                    if (res.ds[i].Approve == 2 && n == data.length - 1) {
                                        that.finalResult = 2;
                                    }

                                    var x = 0;
                                    for (var j in approvalNodeList) {
                                        if (approvalNodeList[j].index == res.ds[i].ApprovalSort) {
                                            x = 1;
                                            approvalNodeList[j].node.push(res.ds[i]);
                                        }
                                    }
                                    if (!x) {
                                        approvalNodeList.push({
                                            index: res.ds[i].ApprovalSort,
                                            type: res.ds[i].FlowType,
                                            department: res.ds[i].ApprovalName,
                                            node: [res.ds[i]]
                                        })
                                    }
                                }
                            }
                            approvalList.push({
                                level: finLevel ? (finLevel - 1) : (level - 1),
                                approvalNodeList: approvalNodeList
                            })
                        }


                        var p1 = 0;
                        var y = 0;
                        if (that.finalResult == 1) {
                            for (var i in res.ds) {
                                if (res.ds[i].Approver && res.ds[i].FlowType != 1) {
                                    p1++;
                                    if (res.ds[i].Approver == that.userData.UserName) {
                                        y = 1;

                                    }
                                }
                            }

                            APP.ajax('getReadUserList', { Ck_ReviewID: that.form.id }, function (res1) {

                                that.readArray = res1.ds;
                                var unReadArray = [];
                                for (var m in res.ds) {
                                    if (res.ds[m].FlowType != 1) {
                                        var z = 0;
                                        for (var n in that.readArray) {
                                            if (res.ds[m].Approver == that.readArray[n].LogCount) {
                                                z = 1;
                                            }
                                        }
                                        if (z == 0) {
                                            unReadArray.push(res.ds[m])
                                        }
                                    }

                                }
                                that.unReadArray = unReadArray;

                                if (y == 1) {
                                    APP.ajax('insertReadReview', { Ck_ReviewID: that.form.id });

                                    var x = 0;
                                    for (var i in res1.ds) {
                                        if (res1.ds[i].UserID == that.userData.UserID) {
                                            x = 1;
                                        }
                                    }
                                    if (x == 0) {
                                        var obj = {
                                            Ck_ReviewID: that.form.id,
                                            ApplyTotalNum: p1,
                                            ReadTotalNum: res1.ds.length + 1
                                        }
                                        APP.ajax('updateCkReviewNum', obj, function (res) {
                                            api.sendEvent({
                                                name: 'refreshList'
                                            });
                                        })
                                    }
                                }

                            })
                        }

                        that.approvalList = approvalList;
                        approvalList[0].approvalNodeList[0].node[0].creater = approvalList[0].approvalNodeList[0].node[0].Creater

                        if (apstatus && that.status == 2 && that.finalResult == 1 && !that.form.isFinish && allCurrentApprovalIDs2.indexOf('19') == -1) {
                            that.closeRow(true);
                        }

                        console.log('approvalList', JSON.stringify(that.approvalList))
                    })
                },
                filterPersonList: function (str, value) {
                    var that = this;
                    var row = null;
                    for (var i in that.personList) {
                        if (that.personList[i][str] == value) {
                            row = that.personList[i];
                            break;
                        }
                    }
                    return row;
                },
                dealApproval(index) {
                    var that = this
                    api.openWin({
                        name: 'approvalDeal',
                        url: 'approvalDeal.html',
                        reload: true,
                        slidBackEnabled: false,
                        allowEdit: true,
                        pageParam: {
                            index: index,
                            status: 1
                        }
                    })
                },
                submitApproval(index, content) {
                    var that = this
                    var obj = {
                        TableName: 'CK_ExperimentPlan',
                        ApprovalSort: 1,
                        ApprovalID: that.approvalID,
                        ApprovalContent: (index == 1 && !content) ? '同意' : content,
                        Approve: index,
                        KeyID: that.form.id,
                        Imgs: ''
                    }
                    APP.ajax('Ck_ApprovalForm', obj, function (res) {
                        // console.log('res', JSON.stringify(res))
                        that.ifConfirm = false;
                        if (res.ds.length && res.ds[0].status && res.ds[0].status == 500) {
                            layer.open({
                                content: res.ds[0].msg,
                                skin: 'msg',
                                time: 2
                            });
                        } else {
                            layer.open({
                                content: '审批成功',
                                skin: 'msg',
                                time: 2
                            });
                            that.initPageData(true);

                            api.sendEvent({
                                name: 'refreshList'
                            });
                        }
                    })
                },
                savePage(flag) {
                    var that = this
                    var obj = {
                        TableName: 'CK_ExperimentPlan',
                        ApprovalSort: that.approvalList[that.approvalList.length - 1].level + 1,
                        ApprovalID: that.approvalID,
                        ApprovalContent: (that.status == 1 && index == 1 && !content) ? '同意' : content,
                        Approve: index,
                        KeyID: that.form.id,
                        Imgs: imgArray ? imgArray.join() : ''
                    }
                    APP.ajax('Ck_ApprovalForm', obj, function (res) {
                        that.ifConfirm = false;
                        if (res.ds.length && res.ds[0].status && res.ds[0].status == 500) {
                            layer.open({
                                content: res.ds[0].msg,
                                skin: 'msg',
                                time: 2
                            });
                        } else {
                            if (reworkDepart) {
                                var obj = {
                                    Ck_ReviewID: that.form.id,
                                    reworkDepart: reworkDepart
                                }
                                APP.ajax('updateReworkDepart', obj, function (res) {
                                    layer.open({
                                        content: '审批成功',
                                        skin: 'msg',
                                        time: 2
                                    });
                                    that.initPageData(true);

                                    api.sendEvent({
                                        name: 'refreshList'
                                    });
                                })
                            } else {
                                layer.open({
                                    content: '审批成功',
                                    skin: 'msg',
                                    time: 2
                                });
                                that.initPageData(true);

                                api.sendEvent({
                                    name: 'refreshList'
                                });
                            }

                        }

                    })
                },
                onClickLeft: function () {
                    var that = this;
                    api.closeWin();
                }
            }
        })
    };
</script>

</html>